﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerSearchMini.aspx.cs"
    Inherits="CrmContacto.WebApp.App.CustomerSearchMini" %>

<%@ Import Namespace="Web.Framework.Translate" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1" runat="server">
    <title></title>
    <link href="/Styles/Site.css" rel="stylesheet" type="text/css" />
    <link href="/Styles/GridStyle.css" rel="stylesheet" type="text/css" />
    <link href="/Styles/jquery-ui-1.8.15.custom.css" rel="stylesheet" type="text/css" />
    <link href="/Styles/jquery.datepick.css" rel="stylesheet" type="text/css" />
    <link href="/Styles/ui.dropdownchecklist.themeroller.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="/Scripts/DirtyCheck.js" type="text/javascript"></script>
    <script src="/Scripts/ajaxupload.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-ui-1.8.15.custom.min.js" type="text/javascript"></script>
    <script src="/Scripts/ErrorPanel.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.datepick.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.datepick-es-AR.js" type="text/javascript"></script>
    <script src="/Scripts/ui.dropdownchecklist.js" type="text/javascript"></script>
    <script src="/Scripts/inputshints.js" type="text/javascript"></script>
    <script src="/Scripts/jqueryWCF.js" type="text/javascript"></script>
    <script src="/Scripts/json2.min.js" type="text/javascript"></script>
    <script src="/Scripts/AppCommon.js" type="text/javascript"></script>
    <script src="/Scripts/CrmCommon.js" type="text/javascript"></script>
    <style type="text/css">
        body
        {
            margin-left: 15px;
            margin-right: 15px;
        }
    </style>
</head>
<body>
    <form id="Form1" runat="server">
    <h2>
        <asp:Image Width="15px" Height="15px" ID="imgExpandResults" CssClass="imgExpand"
            ImageUrl="/Images/icon_blockexpanded.png" runat="server" ClientIDMode="Static"
            alt="" onclick="window.AppCommonObj.toggleVisibility(this.id, 'searchBox');" />
        <asp:Literal ID="Literal22" runat="server" Text='<%$ Code: LocalizationProvider.Instance["Bo.CustomerSearchMini.FilterTitle"]%>' />
    </h2>
    <div class="editionContainerFilter" id="searchBox">
        <p>
            <span class="title2">
                <asp:Literal ID="Literal144" runat="server" Text='<%$ Code:  LocalizationProvider.Instance["Contacto.Nombre"]%>' />:</span>
            <asp:TextBox ID="txtNombre" runat="server" CssClass="inputs inputlong" ClientIDMode="Static"
                title='<%$ Code:  LocalizationProvider.Instance["Contacto.Nombre.Tooltip"] %>'></asp:TextBox>
        </p>
        <p>
            <span class="title2">
                <asp:Literal ID="Literal423" runat="server" Text='<%$ Code:  LocalizationProvider.Instance["Contacto.Apellido"]%>' />:</span>
            <asp:TextBox ID="txtApellido" runat="server" CssClass="inputs inputlong" ClientIDMode="Static"
                title='<%$ Code:  LocalizationProvider.Instance["Contacto.Apellido.Tooltip"] %>'></asp:TextBox>
        </p>
        <div class="clear">
        </div>
        <p>
            <span class="title2">
                <asp:Literal ID="Literal5" runat="server" Text='<%$ Code:  LocalizationProvider.Instance["Contacto.Email"]%>' />:</span>
            <asp:TextBox ID="txtEmail" runat="server" CssClass="inputs inputlong" ClientIDMode="Static"
                title='<%$ Code:  LocalizationProvider.Instance["Contacto.Email.Tooltip"] %>'></asp:TextBox>
        </p>
        <div class="clear">
        </div>
        <p class="lstp">
            <span class="title2">
                <asp:Literal ID="Literal14" runat="server" Text='<%$ Code: LocalizationProvider.Instance["Categorias"]%>' />:</span>
            <asp:ListBox ID="lstCategorias" runat="server" CssClass="lst searchLst" SelectionMode="Multiple"
                ClientIDMode="Static"></asp:ListBox>
        </p>
        <div class="clear">
        </div>
        <p class="lstp">
            <span class="title2">
                <asp:Literal ID="Literal9" runat="server" Text='<%$ Code:  LocalizationProvider.Instance["ListaDeDistribucion"]%>' />:</span>
            <asp:ListBox ID="lstListaDistribucion" runat="server" CssClass="lst searchLst" SelectionMode="Multiple"
                ClientIDMode="Static"></asp:ListBox>
        </p>
        <p class="lstp">
            <span class="title2">
                <asp:Literal ID="Literal2" runat="server" Text='<%$ Code:  LocalizationProvider.Instance["VentaCampanaText"]%>' />:</span>
            <asp:ListBox ID="lstAccionMarketing" runat="server" CssClass="lst searchLst" SelectionMode="Multiple"
                ClientIDMode="Static"></asp:ListBox>
        </p>
        <div class="clear">
        </div>
        <asp:LinkButton ID="lnkBuscar" runat="server" OnClick="lnkBuscar_Click" OnClientClick="return ValidarBuscar();">
            <asp:Literal ID="Literal3" runat="server" Text='<%$ Code: LocalizationProvider.Instance["Bo.Command.Buscar"]%>' /></asp:LinkButton>
        <a href="#" onclick="javascript:document.forms[0].reset();">
            <asp:Literal ID="Literal4" runat="server" Text='<%$ Code: LocalizationProvider.Instance["Bo.Command.Limpiar"]%>' /></a>
        <div class="clear">
        </div>
    </div>
    <div class="clear">
    </div>
    <asp:Panel ID="pnlMessages" runat="server" CssClass="pnlMessagesClass displayNone"
        ClientIDMode="Static">
        <h2>
            <asp:Label ID="txtErrorTitle" runat="server" Text="" CssClass="errorTitle" ClientIDMode="Static"></asp:Label>
        </h2>
        <asp:Panel ID="pnlError" CssClass="errorPanelMessage" ClientIDMode="Static" runat="server">
            <p>
                <asp:Label ID="txtMessages" runat="server" Text="" CssClass="errorMessage" ClientIDMode="Static"></asp:Label>
            </p>
        </asp:Panel>
    </asp:Panel>
    <asp:Panel ID="pnlResultsGroup" runat="server" ClientIDMode="Static" Visible="false">
        <h2>
            <asp:Image Width="15px" Height="15px" ID="Image1" CssClass="imgExpand" ImageUrl="/Images/icon_blockcollapsed.png"
                runat="server" ClientIDMode="Static" alt="" onclick="window.AppCommonObj.toggleVisibility(this.id, 'pnlResults');" />
            <asp:Literal ID="Literal1" runat="server" Text='<%$ Code: LocalizationProvider.Instance["Bo.SearchContacto.ListadoDeClientes"]%>' />
            <asp:Label ID="lblSearchResult" runat="server" Text="" CssClass="lblSearchResult"></asp:Label>
        </h2>
        <asp:Panel ID="pnlResults" CssClass="editionContainerForGrid" runat="server" ClientIDMode="Static">
            <asp:HiddenField ID="hidCheckedRows" runat="server" ClientIDMode="Static" />
            <asp:GridView ID="Grid" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
                AutoGenerateColumns="False" DataKeyNames="Id" Width="100%" AllowPaging="False"
                OnPageIndexChanging="Grid_PageIndexChanging" OnRowCommand="Grid_RowCommand" OnRowDataBound="Grid_RowDataBound">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:TemplateField HeaderText="Incluir">
                        <HeaderStyle HorizontalAlign="Center" Width="30px" />
                        <ItemStyle HorizontalAlign="Center" />
                        <HeaderTemplate>
                            <asp:CheckBox ID="chkSelect" runat="server" CssClass="chkSelectRowHeader" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="chkSelectRow" runat="server" CssClass="chkSelectRow" onclick="javascript:window.AppCommonObj.HandleCheckRow(this);" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Id">
                        <HeaderStyle CssClass="displayNone" />
                        <ItemStyle CssClass="displayNone" />
                        <HeaderTemplate>
                            <span class="displayNone"></span>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <input id="hidenInputRowId_<%# Eval("Email")%>" value="<%# Eval("Email")%>" class="gridid" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Email" HeaderText='<%$ Code:  LocalizationProvider.Instance["Contacto.Email"] %>'
                        SortExpression="Email">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Nombre" HeaderText='<%$ Code:  LocalizationProvider.Instance["Contacto.Nombre"] %>'
                        SortExpression="Nombre">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Apellido" HeaderText='<%$ Code:  LocalizationProvider.Instance["Contacto.Apellido"] %>'
                        SortExpression="Apellido">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                </Columns>
                <EditRowStyle BackColor="#2461BF" />
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#4b6c9e" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
                <PagerStyle BackColor="#4b6c9e" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#EFF3FB" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#F5F7FB" />
                <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                <SortedDescendingCellStyle BackColor="#E9EBEF" />
                <SortedDescendingHeaderStyle BackColor="#4870BE" />
            </asp:GridView>
        </asp:Panel>
        <br />
        <asp:LinkButton ID="lnkGuardar" runat="server" CssClass="guardar" ClientIDMode="Static">
            <asp:Literal ID="Literal6" runat="server" Text='<%$ Code: LocalizationProvider.Instance["Bo.ProductoSearch.Seleccionar"]%>' /></asp:LinkButton>
    </asp:Panel>
    <div class="clear">
    </div>
    
    <script type='text/javascript'>

        $(document).ready(function () {

            if (!window.AppCommonObj) {
                window.AppCommonObj = new AppCommon();
            }

            $('input[title]').inputHints();


            window.AppCommonObj.initializeEnterKeyEvent($('#searchBox'), function () {

                if ($('#lnkBuscar').attr('onclick') != undefined) {
                    if ($('#lnkBuscar').click()) {
                        __doPostBack($('#lnkBuscar').attr('aspnetid'), '');
                    }
                }
            });

            $('.chkSelectRowHeader').change(function () {
                window.AppCommonObj.ToggleSelectAllRows();
            });

            $('.searchLst').dropdownchecklist(
             { icon: {},
                 width: 250,
                 maxDropHeight: 200
             });

            $('#lnkGuardar').click(function () {

                //alert($('#hidCheckedRows').val());
                // window.returnValue = $('#hidCheckedRows').val();
                // window.close();

                parent.SearchMiniJsObj.SeleccionarValores();
                return false;
            });

        });

        function GetSelectedValues() {

            return $('#hidCheckedRows').val();
        };

        function isValidEmailAddress(emailAddress) {
            //var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
            var pattern = new RegExp(/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i);
            return pattern.test(emailAddress);
        };

        // Validación
        function ValidarBuscar() {
            var errorPanel = new ErrorPanel();

            var isError = false;
            var strError = '';

            errorPanel.removeErrors();
            var txtNombre = $('#txtNombre');
            var txtApellido = $('#txtApellido');
            var txtEmail = $('#txtEmail');
            var lstCategorias = $('#lstCategorias');
            var lstListaDistribucion = $('#lstListaDistribucion');
            var lstAccionMarketing = $('#lstAccionMarketing');

            var separador = '';

            var nombreVacio = txtNombre.val() == '' || txtNombre.val() == txtNombre.attr('title');
            var apellidoVacio = txtApellido.val() == '' || txtApellido.val() == txtApellido.attr('title');
            var emailVacio = txtEmail.val() == '' || txtEmail.val() == txtEmail.attr('title');
            
            var categoriaVacio = lstCategorias.val() == null;
            var listaVacio = lstListaDistribucion.val() == null;
            var accionVacio = lstAccionMarketing.val() == null;

            if (nombreVacio && apellidoVacio && emailVacio && categoriaVacio && listaVacio && accionVacio) {
                isError = true;
                errorPanel.appendAsteriskToJQControl(txtNombre);
                errorPanel.appendAsteriskToJQControl(txtApellido);
                errorPanel.appendAsteriskToJQControl(txtEmail);
                errorPanel.appendAsteriskToJQControl($('#ddcl-lstCategorias'));
                errorPanel.appendAsteriskToJQControl($('#ddcl-lstListaDistribucion'));
                errorPanel.appendAsteriskToJQControl($('#ddcl-lstAccionMarketing'));
                //errorPanel.appendAsteriskToJQControl(listaVacio);

                strError += separador;
                strError += JsLocalization_CustomerSearchMiniJs_IngreseTodosLosCampos;
                separador = '<br />';
            }

            if (!nombreVacio && txtNombre.val().length < 3) {
                isError = true;
                errorPanel.appendAsteriskToJQControl(txtNombre);
                errorPanel.appendAsteriskToJQControl(txtApellido);
                errorPanel.appendAsteriskToJQControl(txtEmail);

                strError += separador;
                strError += JsLocalization_CustomerSearchMiniJs_IngreseNombre;
                separador = '<br />';
            }

            if (!apellidoVacio && txtApellido.val().length < 3) {
                isError = true;
                errorPanel.appendAsteriskToJQControl(txtApellido);

                strError += separador;
                strError += JsLocalization_CustomerSearchMiniJs_IngreseApellido;
                separador = '<br />';
            }

            if (!emailVacio && !isValidEmailAddress(txtEmail.val())) {
                isError = true;
                errorPanel.appendAsteriskToJQControl(txtEmail);

                strError += separador;
                strError += JsLocalization_CustomerSearchMiniJs_IngreseUnEmailValido;
                separador = '<br />';
            }

            if (isError) {
                errorPanel.showError(JsLocalization_Messages_CompleteElFormulario, strError);
            }

            return !isError;
        }

    </script>
    </form>
</body>
</html>
